package trip;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.GenerationType;
import javax.persistence.ManyToOne;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;

@Entity
@Table(name = "TRIP")
public class Trip {
	@Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;

	@Column(name = "number", nullable = false)
	private Integer number;

	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "route_id")
	private Route route;

	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name = "company_id")
	private Company company;

	@Column(name = "seats", nullable = false)
	private Integer seats;

	//constructors
	public Trip() {};
	
	public Trip(long id, Integer number, Route route, Company company, Integer seats) {
		this.id = id;
		this.number = number;
		this.route = route;
		this.company = company;
		this.seats = seats;
	}
	
	//id
	public long getId() {
		return id;
	}

	public Trip setId(long id) {
		this.id = id; 
		return this;
	}

	//number
	public Integer getNumber() {
		return number;
	}

	public Trip setNumber(Integer number) {
		this.number = number;
		return this;
	}

	//route
	public Route getRoute() {
		return route;
	}
	
	public Trip setRoute(Route route) {
		this.route = route;
		return this;
	}

	//company
	public Company getCompany() {
		return company;
	}

	public Trip setCompany(Company company) {
		this.company = company;
		return this;
	}
	
	//seats
	public Integer getSeats() {
		return seats;
	}

	public Trip setSeats(Integer seats) {
		this.seats = seats;
		return this;
	}
	
	public boolean equals(Trip trip) {
		if (trip == null)
			return false;
		if (this.id == trip.id && 
			this.number == trip.number &&
			this.route.equals(trip.route) &&
			this.company.equals(trip.company) &&
			this.seats == trip.seats) 
			return true;
		else
			return false;
	}
}	